package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.WenContent;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.IWenContentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 文案内容Controller
 * 
 * @author ruoyi
 * @date 2023-02-09
 */
@RestController
@RequestMapping("/wenan/content")
public class WenContentController extends BaseController
{
    @Autowired
    private IWenContentService wenContentService;

    /**
     * 查询文案内容列表
     */
    @PreAuthorize("@ss.hasPermi('wenan:content:list')")
    @GetMapping("/list")
    public TableDataInfo list(WenContent wenContent)
    {
        startPage();
        List<WenContent> list = wenContentService.selectWenContentList(wenContent);
        return getDataTable(list);
    }

    /**
     * 导出文案内容列表
     */
    @PreAuthorize("@ss.hasPermi('wenan:content:export')")
    @Log(title = "文案内容", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WenContent wenContent)
    {
        List<WenContent> list = wenContentService.selectWenContentList(wenContent);
        ExcelUtil<WenContent> util = new ExcelUtil<WenContent>(WenContent.class);
        util.exportExcel(response, list, "文案内容数据");
    }

    /**
     * 获取文案内容详细信息
     */
    @PreAuthorize("@ss.hasPermi('wenan:content:query')")
    @GetMapping(value = "/{wid}")
    public AjaxResult getInfo(@PathVariable("wid") Long wid)
    {
        return success(wenContentService.selectWenContentByWid(wid));
    }

    /**
     * 新增文案内容
     */
    @PreAuthorize("@ss.hasPermi('wenan:content:add')")
    @Log(title = "文案内容", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WenContent wenContent)
    {
        return toAjax(wenContentService.insertWenContent(wenContent));
    }

    /**
     * 修改文案内容
     */
    @PreAuthorize("@ss.hasPermi('wenan:content:edit')")
    @Log(title = "文案内容", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WenContent wenContent)
    {
        return toAjax(wenContentService.updateWenContent(wenContent));
    }

    /**
     * 删除文案内容
     */
    @PreAuthorize("@ss.hasPermi('wenan:content:remove')")
    @Log(title = "文案内容", businessType = BusinessType.DELETE)
	@DeleteMapping("/{wids}")
    public AjaxResult remove(@PathVariable Long[] wids)
    {
        return toAjax(wenContentService.deleteWenContentByWids(wids));
    }
}
